﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MajorStudentGroup.aspx.cs"
    Inherits="ZX.WebApp.Crm.MajorStudentGroup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.calendar.js" type="text/javascript"></script>
    <link href="../../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="fieldTable">
            <tr>
                <td style="width:80px;">
                    团号：<span style="color: Red">*</span>
                </td>
                <td>
                    <input type="text" id="GroupName" runat="server"
                         onfocusout="return LoadAssistance(this.value);" style="width: 150px;" />
                    <span id="txtMsg" style="color:Red;"></span>
                </td>
            </tr>
            <tr>
                <td>
                    辅导员：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <input type="hidden" id="Assistance" runat="server" />
                    <input runat="server" type="text" id="txtAssistance" name="txtAssistance" readonly="readonly"
                        style="width: 150px;" />
                    <button id="btnAssistance" name="Z" type="button" class="btnCheck" style="width: 50px;">
                        选择</button>
                </td>
            </tr>
            <tr>
                <td>
                    备注：
                </td>
                <td>
                    <textarea rows="5" cols="40" id="Explain" runat="server"></textarea>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
<script type="text/javascript">
    var instance = [{ "Exp1": "", "GroupName": "", "Assistance": "", "Explain": ""}];
    var StudentIds = parent.ids;
    function Save() {
        for (var i = 0; i < StudentIds.length; i++) {
            instance[0].Exp1 += StudentIds[i] + "#";
        }
        instance[0].GroupName = $("#GroupName").val();
        instance[0].Assistance = $("#Assistance").val();
        instance[0].Explain = $("#Explain").val();
        if (instance[0].GroupName == "") {
            parent._state = "";
            alert("团号不能为空！");
            return;
        }
        if (instance[0].Assistance == "") {
            //parent._state = "0";
            //alert("辅导员不能为空！");
            //return;
            instance[0].Assistance = "00000000-0000-0000-0000-000000000000";
        }
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        SaveData(json);
    }
    function SaveData(obj) {
        YAHOO.util.Connect.asyncRequest('POST', '../../Extend/AjaxData/CustomOperating.aspx?action=update&entity=CrmMajorStudent_G&json=' + encodeURI(obj), {
            success: function (res) {
                var inventory;
                try {
                    inventory = res.responseText;
                    if (inventory == "1") {
                        parent._state = "0";
                        alert("学员分团成功!");
                        parent.ReLoadData();
                    } else {
                        alert("保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
    //检查团中是否已有辅导员
    function LoadAssistance(val) {
        var condition = encodeURI("GroupName='" + val + "'");
        YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmDeliverMajorStudent&customCondition=" + condition + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                var arr = eval(str);
                if (arr[0].AssistanceName != "") {
                    $("#Assistance").val(arr[0].Assistance);
                    $("#txtAssistance").val(arr[0].AssistanceName);
                    $("#txtMsg").text("该团中已有辅导员!");
                }
            }
            catch (e) {
                $("#Assistance").val("");
                $("#txtAssistance").val("");
                $("#txtMsg").text("");
            }
            finally {
            }
        }, failure: function () { }
    });
    }
</script>
</html>
